
import {formatTime} from '../utils/utils'

Page({
    data:{
        logs: [],
        activeIndex:0,
        dayList:[],
        list:[],
        staList:[
            {
              title:'番茄次数',
              val:'0'
            },
            {
              title:'专注时长',
              val:'0分钟'
            }
          ],
        allList:[
            {
              title:'番茄次数',
              val:'0'
            },
            {
                title:'专注时长',
                val:'0分钟'
            }
        ]
    },
    onLoad(){
        var logs = wx.getStorageSync('logs') || [];
        var day = 0;
        var total = logs.length;
        var dayTime = 0;
        var totalTime = 0;
        var dayList = [];
        if(logs.length > 0){
            for(var i = 0;i < logs.length;i++){
            let a = logs[i].date + ""
            let b = formatTime(new Date) + ""
                if(a.slice(0,10) == b.slice(0,10)){
                console.log(formatTime(new Date))
                day = day + 1;
                dayTime = dayTime + parseInt(logs[i].time);
                dayList.push(logs[i]);
                this.setData({
                    dayList:dayList,
                    list:dayList
                })
                }
            totalTime = totalTime + parseInt(logs[i].time);
            }
            this.setData({
                'staList[0].val':day,
                'allList[0].val':total,
                'staList[1].val':dayTime+'分钟',
                'allList[1].val':totalTime+'分钟'
            })
        }
    },
    changeType(e){
        var index = e.currentTarget.dataset.index;
        if(index == 0){
          this.setData({
            list:this.data.dayList
          })
        }else if(index == 1){
          var logs = wx.getStorageSync('logs') || [];
          this.setData({
            list:logs
          })
        }
        this.setData({
          activeIndex:index
        })
    }
})